//
//  PicCollectionView.swift
//  weibo
//
//  Created by 叶子韬韬 on 2017/5/5.
//  Copyright © 2017年 叶子韬韬. All rights reserved.
//

import UIKit

class PicCollectionView: UICollectionView {

    
    var picUrl:[URL] = [URL](){
        didSet{
            
            self.reloadData()
        }
    }
    
    
    override func awakeFromNib() {
        dataSource = self
        delegate = self
        
    }

}
// MARK:- #注释>collectionView 数据源代理
extension PicCollectionView : UICollectionViewDataSource,UICollectionViewDelegate{
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return picUrl.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "PicCell", for: indexPath) as! PicCollectionviewCell
        
        cell.picUrl = picUrl[indexPath.item]
        
        return cell
        
    }
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        
        
        //1.获取通知要传递的参数
        //2.所有图片的url
        
        let userInfo = ["indexPath":indexPath,"picUrls":picUrl] as [String : Any]
        
        NotificationCenter.default.post(name:NSNotification.Name(rawValue: ShowPhotoNotific) , object: nil, userInfo: userInfo)
        
        
    }
    
}



